package com.hg.concurent.demo8;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: skh
 * @Date: 2019/12/25 14:23
 * @Description:
 */
public class Singleton03 {

    private  static volatile Singleton03 instance = null;

    private Singleton03() {
        System.out.println(Thread.currentThread().getName() + "执行构造方法");
    }

    public static Singleton03 getInstance() {
        if (instance == null) {
            synchronized (Singleton03.class) {
                if (instance == null) {
                    instance = new Singleton03();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        for (int i = 0; i < 100; i++) {
            executorService.execute(() -> {
                Singleton03.getInstance();
            });
        }

        executorService.shutdown();
    }
}
